

*** I) this do-file processes the raw data from https://www.worldmrio.com/eora26/ on trade flows and total output in 2015
***** and produces input for matlab (baseline of the counterfactual experiment)

*** II) it produces the country pair specific cost shocks using the exposure indicator and the estimated coefficients


****************************************************************************************************************************************
********************************** I)
****************************************************************************************************************************************

global main /Users/inga/Dropbox/Ais project/counterfactual
global rawdata $main/raw_data/Eora26_2015_pp
global data $main/data
global datasource "/Users/inga/Dropbox/Ais project/BoxAccounting/data2/PREPOST"


import delim using "$rawdata/labels_T.txt", clear

rename v2 iso_s

g c_s=ceil(_n/26)
g sec_s=_n-(c_s-1)*26

g sector_s = 1 if sec_s<12
replace sector_s = 2 if sec_s>11

drop v1 v3-v5 c_s

g n=_n

save "$data/labels_T4m", replace



** prep intermediate goods sales/exports

import delim using "$rawdata/Eora26_2015_bp_T.txt", clear

g n=_n
merge 1:1 n using "$data/labels_T4m"
drop _merge n

* column names 
forvalues i=1(1)4915 {
global iso = iso_s[`i']
global sec= sec_s[`i']
rename v`i' ie${iso}${sec}
}


* aggregate columns

/*drop ROW residual and USSR (should be zero according to EORA, but has small positive entries*/
drop ieROW* ieUSR*
drop if iso_s=="ROW" | iso_s=="USR"
drop if sec_s==26
drop *26

levelsof iso_s, local(isolist)
foreach iso in `isolist' {
egen i`iso'1=rowtotal(ie`iso'1-ie`iso'11)
egen i`iso'2=rowtotal(ie`iso'12-ie`iso'25)
drop ie`iso'*
}

* aggregate rows

rename iso siso
collapse (sum) i*, by(siso sector_s)
rename siso iso_s

save "$data/iexp", replace





****** pre final sales/exports



import delim using "$rawdata/Eora26_2015_bp_FD.txt", clear

g n=_n
merge 1:1 n using "$data/labels_T4m"
drop _merge n

*drop ROW in rows
drop if iso_s=="ROW"
drop if sec_s==26
*drop ROW in columns
drop v1135-v1140

g one = 1 if sec_s==1

local i=1
forvalues k=1(25)4701 {
local iso=iso_s[`k']
forvalues j=1(1)6 {
rename v`i' fd`iso'`j'
local i=`i'+1
}
}

drop fdUSR*
drop if iso_s=="USR"


*THIS DOESNT WORK BECAUSE COUNTRIES ARE NOT SORTED ALPHABETICALLY BY ISO CODES (BUT RATHER COUNTRY NAMES)
* LEVELSOF IS ALPHABETICALLY SORTED
/*
*name columns (each country has six final demand categories)
levelsof iso_s, local(isolist)
local i=1
foreach iso in `isolist' {
forvalues j=1(1)6 {
rename v`i' fd`iso'`j'
local i=`i'+1
}
}
*/


* aggregate columns over final demand categories
levelsof iso_s, local(isolist)
foreach iso in `isolist' {
egen f`iso'=rowtotal(fd`iso'*)
drop fd`iso'*
}

* aggregate rows
collapse (sum) f*, by(iso sector_s)

* merge intermediate goods sales
merge 1:1 iso sector using "$data/iexp"
drop _merge

* aggregate columns over demanding sectors (intermediates to manu/services and final sales)
levelsof iso_s, local(isolist)
foreach iso in `isolist' {
egen exp`iso'=rowtotal(*`iso'*)
drop i`iso'* f`iso'
}

*reshape long exp, i(iso_s sec) j(iso_d) string
*reshape wide exp, i(iso_d sec) j(iso_s) string

sort iso_s sec

* exporters in rows, importers in columns
export delim exp* using "$main/MATLAB/exp.txt" if sec==1, replace novarname

save "$data/mrio2015", replace



cd "/Users/inga/Dropbox/Ais project/inga"

global mrio "/Users/inga/Dropbox (UiO)/Ais project/counterfactual/data"
global data "data"

u "$mrio/mrio2015", clear
*keep if sec==1
collapse (sum) exp*, by(sector_s)

reshape long exp, i(sec) j(iso) string

reshape wide exp, i(iso) j(sec)

rename exp1 Emanu
rename exp2 Eserv

save "$data/Expenditure", replace


** get services/manufacturing split for islands where we have it

u $data/Expenditure, clear
g alpha=Emanu/(Emanu+Eserv)
sum alpha if iso=="ATG" | iso=="ANT"  | iso=="BHS"  | iso=="BMU"  | iso=="BRB" | iso=="CPV" | iso=="DOM" | iso=="FJI" | iso=="HTI" | iso=="JAM"  | iso=="MRT" | iso=="NCL" | iso=="PYF" | iso=="STP" | iso=="SYC" | iso=="TTO" | iso=="VUT" | iso=="WSM"

** = .31 -- applied below


import excel using "/Users/inga/Dropbox (UiO)/Ais project/inga/raw data/WDI/Popular Indicators.xlsx", clear firstrow
drop Series*

drop if CountryCode==""
drop if YR==".."
destring YR, replace

global N = _N+5
set obs $N


g inEUR=.
replace CountryCode="MTQ" in 207 /*https://www.insee.fr/en/statistiques/serie/010751762*/
replace inEUR = 8675000 in 207
replace CountryCode="GLP" in 208 /*https://www.insee.fr/en/statistiques/serie/010751761*/
replace inEUR = 8574000 in 208
replace CountryCode="MYT" in 209  /*https://www.insee.fr/en/statistiques/serie/010751764*/
replace inEUR = 2079000 in 209
replace CountryCode="REU" in 210
replace inEUR = 17555000 in 210 /*https://www.insee.fr/en/statistiques/serie/010751763*/
replace CountryCode="GUF" in 211 /*https://www.insee.fr/en/statistiques/serie/010751772*/
replace inEUR = 3993000 in 211 
replace YR=1.1095*inEUR if YR==. /*https://sdw.ecb.europa.eu/quickview.do?SERIES_KEY=120.EXR.A.USD.EUR.SP00.A*/
drop *Name inEUR


*convert to thousand USD to correspond to MRIO

replace YR=YR/1000

save $data/GDP4islands, replace




*********** break down to ports

*** generate relative port size for multiple ports within countries, use only pre-period

u "/Users/inga/Dropbox (UiO)/Ais project/AER rr task-yuan/Data/port-pairs-data2",replace
keep if post==0
collapse (sum) traffic_dwt, by(A_country A_port_name)
save "$data/traffic_port", replace


u "/Users/inga/Dropbox (UiO)/Ais project/inga/data/portlistAA", clear
rename A_coun iso2
merge m:1 iso2 using "/Users/inga/Dropbox (UiO)/Ais project/inga/data/iso2toiso3_uqe", keepusing(iso3)
replace iso3="TWN" if iso2=="TW"
replace iso3="PRI" if iso2=="PR"
drop if _merge==2
drop _merge 
rename A_name A_port_name

rename iso2 A_country
merge 1:1 A_port_name A_country using "$data/traffic_port"
drop if _merge==2
drop _merge

g iso = iso3
replace iso="SUD" if iso=="SDN"
replace iso="ANT" if iso=="CUW"
replace iso="ANT" if iso=="SXM"

merge m:1 iso using "$data/Expenditure"
drop if _merge==2
drop _merge

rename iso CountryCode
merge m:1 Coun using "$data/GDP4islands"
drop if _merge==2
drop _merge

g E=Emanu+Eserv
g GDP_E=YR/E

sum GD
count if GD>1


** calculate average relationship between GDP and expenditure for similar islands

g alpha=Emanu/(Emanu+Eserv)

bysort iso: g n=_n
sum alpha if n==1 & (iso=="ATG" | iso=="ANT"  | iso=="BHS"  | iso=="BMU"  | iso=="BRB" | iso=="CPV" | iso=="DOM" | iso=="FJI" | iso=="HTI" | iso=="JAM"  | iso=="MRT" | iso=="NCL" | iso=="PYF" | iso=="STP" | iso=="SYC" | iso=="TTO" | iso=="VUT" | iso=="WSM")
global alpha=r(mean)
sum GD if n==1 & (iso=="ATG" | iso=="ANT"  | iso=="BHS"  | iso=="BMU"  | iso=="BRB" | iso=="CPV" | iso=="DOM" | iso=="FJI" | iso=="HTI" | iso=="JAM"  | iso=="MRT" | iso=="NCL" | iso=="PYF" | iso=="STP" | iso=="SYC" | iso=="TTO" | iso=="VUT" | iso=="WSM")
global beta=r(mean)

tab Country if E==.

* extrapolate expenditures using alpha and beta

replace E=YR/$beta if E==.
replace Emanu= $alpha*E if Emanu==.

keep A_acid A_port_name A_country E Emanu line traffic
sort line

egen Traffic=total(traffic), by(A_coun)
g Emanu_port = traffic/Traffic*Emanu
g E_port = traffic/Traffic*E
drop E Emanu Traffic

label var E_port "expenditure by port in 1000 USD, 2015"
label var Emanu_port "expenditure on manufacturing goods, by port in 1000 USD, 2015"

sort line
save "$data/Expenditure_port", replace

erase "$data/GDP4islands.dta"
erase "$data/traffic_port.dta"
erase "$data/Expenditure.dta"






** number of countries with one port

u "/Users/inga/Dropbox (UiO)/Ais project/inga/data/portlistAA", clear
collapse (count) A_acid, by(A_country)
count if A_ac==1
di r(N)/_N



Completely agree - I am also an ENTJ but still respect boundaries. 

I think my heart interpreted these actions as a sign of vast love, but my gut interpreted it as manipulative and something I should stay far away from. I think this has been part of the deeper problem - that my gut and heart have been so completely divided - fighting bitterly against each other.

Thanks for the reference to "euphoric recall" - you are absolutely right: I've been replaying the highs while muting the harm. I think I need to define myself as an addict and take steps to recover from there.

The triangulation piece really hit me. I hadn’t named it that way, but it’s pretty clear. I felt ambushed by the meeting with her psychologist friend. I felt exposed when she messaged my parents. I felt deeply uncomfortable when she wrote to my wife. But I also overrode my discomfort, again and again — because I wanted to believe it was love, not control. But as you said: it’s not about her words, it’s about her behavior.

Working hard here to choose reality, day by day, instead of fog.

